
class ImageSequence:
	def __init__(self, format = "", fileLister = None):
		self.setFormat(format)
		self.setFileLister(fileLister)
		
		
	def setFormat(self, format):
		self.format = format
		
		
	def setFileLister(self, fileLister):
		self.fileLister = fileLister

		
	def isValid(self):
		if not self.format.endswith(".#.dpx"):
			return False
		
		return True
	
	
	def fileMatches(self, file):
		frameStr = file[-8:-4]
		
		try:
			_frameNr = int(frameStr)
		except:
			return False
		
		start = file[:-8]
		end = file[-4:]
		
		return (start + "#" + end) == self.format
		
	
	def getFilesThatMatch(self, files):
		matchedFiles = []
		for file in files:
			if self.fileMatches(file):
				matchedFiles.append(file)
				
		return matchedFiles
		
	
	def getFilesThatMatchInDir(self, dir):
		files = self.fileLister.listFiles(dir)
		return self.getFilesThatMatch(files)
		
